import datetime
import uuid

import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, VARCHAR, DATETIME, func, ForeignKey, BOOLEAN
from config.mysql import engine

metadata = sqlalchemy.MetaData()

User = sqlalchemy.Table(
    "user",
    metadata,
    sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
    sqlalchemy.Column("name", sqlalchemy.String(50)),
    sqlalchemy.Column("member", sqlalchemy.Boolean),
    sqlalchemy.Column("createDate", sqlalchemy.DATETIME, default=datetime.datetime.now)
)


UserChatRecord = sqlalchemy.Table(
    "user_chat_record",
    metadata,
    sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
    sqlalchemy.Column("userId", sqlalchemy.Integer),
    sqlalchemy.Column("userName", sqlalchemy.VARCHAR(50)),
    sqlalchemy.Column("content", sqlalchemy.TEXT(), nullable=True),
    sqlalchemy.Column("createDate", sqlalchemy.DATETIME(), default=datetime.datetime.now)
)


WatchStatistics = sqlalchemy.Table(
    "watch_statistics",
    metadata,
    sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
    sqlalchemy.Column("liveId", sqlalchemy.VARCHAR(30)),
    sqlalchemy.Column("enterpriseId", sqlalchemy.VARCHAR(30)),
    sqlalchemy.Column("userId", sqlalchemy.VARCHAR(50)),
    sqlalchemy.Column("inviter", sqlalchemy.VARCHAR(50), nullable=True),
    sqlalchemy.Column("agentUser", sqlalchemy.VARCHAR(50), nullable=True),
    sqlalchemy.Column("ip", sqlalchemy.VARCHAR(250), nullable=True),
    sqlalchemy.Column("duration", sqlalchemy.DECIMAL(12, 2), nullable=True),
    sqlalchemy.Column("unique", sqlalchemy.String(32), default=uuid.uuid4().hex, unique=True),
    sqlalchemy.Column("startDate", sqlalchemy.DATETIME(), nullable=True),
    sqlalchemy.Column("endDate", sqlalchemy.DATETIME(), nullable=True),
    sqlalchemy.Column("createDate", sqlalchemy.DATETIME, default=datetime.datetime.now),
    sqlalchemy.Column("updateDate", sqlalchemy.DATETIME(), default=datetime.datetime.now)
)


metadata.create_all(engine)


